<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="css/layui.css" media="all">
    <script src="js/layui.all.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
    <style>
        body {
            margin-left: 10px;
        }

        button {
            margin-top: 10px;
            width: 120px;
            height: 30px;
        }

        div {
            margin-top: 10px;
        }
    </style>

</head>

<body>
<div>
    <div>
        <div>1.登陆</div>
        <div>

            <div>身份证号：<input id="txtFcardno" value="420984198611138035" /></div>
            <div>姓名：<input id="txtFname" value="黄正谱" /></div>
            <div>手机号：<input id="txtPhone" value="13667152307" /></div>
            <div>验证码：<input id="txtPwd"  /></div>
            <div>custfnocookie：<input id="fno" /><label style="color:blue">从首页里面的cookie里面找到</label></div>
            <div>
                <button onclick="getCheckCode()">①获取验证码</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <button onclick="login()">②登陆</button>
                <button onclick="loginURL()" style="display:none">登陆URL</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <button onclick="mainURL()">首页</button>
            </div>


        </div>
    </div>

    <div style="margin-top: 20px;">
        <div>2.资料上传</div>
        <div>
            <div>a.身份证<label id="demo11"></label></div>
            <div>
                <center>
                    <button class="layui-btn layui-btn-danger btnupimp" style=" width:90%; " id="test1" type="button">
                        <i class="layui-icon"></i>③身份信息(上传)
                    </button>
                    <div class="layui-inline layui-word-aux"></div>
                    <br/>
                    <div class="layui-upload-img" style=" border:1px solid red; padding:10px; " id="demo1"> </div>
                </center>
            </div>
        </div>
        <div style="margin-top: 20px;">
            <div>3.提交申请</div>
            <div>
                <button onclick="submitInfo()">④提交</button>
            </div>
        </div>
        <div>
            <div>b.户口<label id="demo22"></label></div>
            <div>
                <center>
                    <button class="layui-btn layui-btn-danger btnupimp" style=" width:90%; " id="test2" type="button">
                        <i class="layui-icon"></i>户口信息(上传)
                    </button>
                    <div class="layui-inline layui-word-aux"></div>
                    <br/>
                    <div class="layui-upload-img" style=" border:1px solid red; padding:10px; " id="demo2"> </div>
                </center>
            </div>
        </div>
        <div>
            <div>c.婚姻状况<label id="demo44"></label></div>
            <div>
                <center>
                    <button class="layui-btn layui-btn-danger btnupimp" style=" width:90%; " id="test4" type="button">
                        <i class="layui-icon"></i>婚姻状况信息(上传)
                    </button>
                    <div class="layui-inline layui-word-aux"></div>
                    <br/>
                    <div class="layui-upload-img" style=" border:1px solid red; padding:10px; " id="demo4"> </div>
                </center>
            </div>
        </div>
        <div style="display:none">
            <div>d.房查<label id="demo55"></label></div>
            <div>
                <center>
                    <button class="layui-btn layui-btn-danger btnupimp" style=" width:90%; " id="test5" type="button">
                        <i class="layui-icon"></i>房查信息(上传)
                    </button>
                    <div class="layui-inline layui-word-aux"></div>
                    <br/>
                    <div class="layui-upload-img" style=" border:1px solid red; padding:10px; " id="demo5"> </div>
                </center>
            </div>
        </div>
        <div>
            <div>d.验资证明<label id="demo66"></label></div>
            <div>
                <center>
                    <button class="layui-btn layui-btn-danger btnupimp" style=" width:90%; " id="test6" type="button">
                        <i class="layui-icon"></i>验资证明(上传)
                    </button>
                    <div class="layui-inline layui-word-aux"></div>
                    <br/>
                    <div class="layui-upload-img" style=" border:1px solid red; padding:10px; " id="demo6"> </div>
                </center>
            </div>
        </div>
        <div>
            <div>e.征信<label id="demo77"></label></div>
            <div>
                <center>
                    <button class="layui-btn layui-btn-danger btnupimp" style=" width:90%; " id="test7" type="button">
                        <i class="layui-icon"></i>征信(上传)
                    </button>
                    <div class="layui-inline layui-word-aux"></div>
                    <br/>
                    <div class="layui-upload-img" style=" border:1px solid red; padding:10px; " id="demo7"> </div>
                </center>
            </div>
        </div>
    </div>

</div>
<script type="text/javascript">
    var layer;
    var imgupsize = 5;
    var userpwd = "";
    var fno = "";

    layui.use(['form'], function() {
        var form = layui.form,
            layer = layui.layer;

        /**var userpwd = getCookie("userpwd");
         $("#txtPwd").val(userpwd);
         var custfnocookie = getCookie("custfnocookie");
         $("#fno").val(custfnocookie);
         layer.msg("OK:pwd > "+userpwd+",fno > "+custfnocookie);**/

        $("#txtPwd").val(userpwd);
        $("#fno").val(fno);
        //layer.msg("OK:pwd > "+userpwd+",fno > "+fno);
    });

    function getCheckCode() {
        var idcard = $("#txtFcardno").val();
        var txtFname = $("#txtFname").val();
        var phone = $("#txtPhone").val();
        var userpwd = $("#txtPwd").val();

        var urlUser = "http://gxzlsq.taiyuehd.net/ajax.aspx?type=getYZMTy" + "&idcard=" + escape($("#txtFcardno").val()) +
            "&phone=" + escape($("#txtPhone").val()) + "&userpwd=" + escape($("#txtPwd").val()) + "&t=" + new Date();

        $.ajax({
            url: urlUser,
            async: false,
            dataType: "text",
            success: function(data) {
                if(data == "登录成功") {
                    layer.msg(data);
                } else {
                    layer.msg(data);
                }
            },
            error: function(edata) {
                console.log(JSON.stringify(edata));
                layer.msg("请求失败：" + JSON.stringify(edata));
            }
        });

    }

    function login() {
        var urlUser = "http://gxzlsq.taiyuehd.net/ajax.aspx?type=CustLoginFst" + "&txtFname=" + escape($("#txtFname").val()) + "&idcard=" + escape($("#txtFcardno").val()) +
            "&phone=" + escape($("#txtPhone").val()) + "&userpwd=" + escape($("#txtPwd").val()) + "&t=" + new Date();
        setCookie("userpwd",$("#txtPwd").val());
        $.ajax({
            url: urlUser,
            async: false,
            dataType: "text",
            success: function(data) {
                if(data == "登录成功") {
                    layer.msg(data);
                } else {
                    layer.msg(data);
                }
                console.log(data);
                submitInfo();
                //window.open("http://gxzlsq.taiyuehd.net/wap/tyhome.htm");
            },
            error: function(edata) {
                console.log(JSON.stringify(edata));
                layer.msg("请求失败：" + JSON.stringify(edata));
            }
        });

    }

    function submitInfo() {
        var idcard = $("#txtFcardno").val();
        //flm 是否联名    bdhk 本地户口   fcardno 证件号码      fwcn 未成年子女  fhyzk   婚姻状况 3已婚     fkfs 付款方式 2商代
        $.ajax({
            url: "http://gxzlsq.taiyuehd.net/ajax.aspx?type=SQTJ&flm=0&bdhk=1&fcardno=" + idcard + "&fwcn=0&fhyzk=1&fkfs=2&ftj=1&t=" + new Date(),
            async: false,
            dataType: "text",
            success: function(datax) {
                console.log(datax);
                layer.msg(datax);
                if(datax == '请上传相关图片！') {
                    layer.msg(datax);
                    return;
                }
                if(datax == '申请人数已满！') {
                    layer.msg(datax);
                    return false;
                }

            },
            error: function(edata) {
                console.log(JSON.stringify(edata));
                layer.msg("请求失败：" + JSON.stringify(edata));
            }
        });
    }


    function getCookie(name) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg))
            return unescape(arr[2]);
        else
            return "";
    }

    //写cookies
    function setCookie(name, value) {
        var Days = 30;
        var exp = new Date();
        exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
        document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
    }

    layui.use('upload', function() {
        var $ = layui.jquery,
            upload = layui.upload;
        var fnames = ['身份证', '户口', '社保', '婚姻状况', '房产', '收入', '征信'];
        for(var tempIndex = 1; tempIndex <= fnames.length; tempIndex++) {
            var curfName= fnames[tempIndex - 1];
            if(tempIndex == 3 || tempIndex == 5){
                continue;
            }
            upload.render({
                elem: '#test'+tempIndex,
                id: new Date().getTime(),
                size: 2 * 1024, //限制文件大小，单位 KB
                ext: 'bmp', //那么，就只会支持这三种格式的上传。注意是用|分割。
                url: 'http://gxzlsq.taiyuehd.net/Management/UploadFile.aspx?fname=' + escape(fno) + '&ftype=' + escape(curfName) + "&t=" + new Date(),
                auto: false,
                choose: function(obj) {
                    obj.preview(function(index, file, result) {

                        if((file.size / 1000) < imgupsize) {
                            layer.msg('图片不能小于' + imgupsize + 'K');
                        } else obj.upload(index, file); //文件上传

                    });
                },
                before: function(obj) {
                    layer.msg('文件开始上传，请等待');
                },
                done: function(res) {
                    var resultStr = JSON.stringify(res)
                    var curIndex = resultStr.substring(resultStr.lastIndexOf("/") - 1,resultStr.lastIndexOf("/"));
                    layer.msg(curIndex+'>上传成功:'+JSON.stringify(res));
                    //如果上传失败
                    if(res.code > 0) {
                        return layer.msg('上传失败');
                    } else {

                        $('#demo'+curIndex).append('<div id="divimg-' + res.fid + '" ><img id="img-' + res.fid + '" height="150px" width="200px" src="' + res.data.src + '" alt="' + '' +
                            '" class="layui-upload-img"><br/><p id="delimg-' + res.fid + '"       class="glyphicon glyphicon-trash" style=" margin:5px; font-size:18px;background:red; color:white; " >删除</p><br/></div>');

                        var xtypex = ''+curIndex;
                        if($('#demo' + xtypex + xtypex + ' .layui-badge').html() == undefined) $('#demo' + xtypex + xtypex + '').append('<span class="layui-badge">0</span>');
                        $('#demo' + xtypex + xtypex + ' .layui-badge').html($('#demo' + xtypex + xtypex + ' .layui-badge').html() * 1 + 1);

                    }
                    if($('#demo' + xtypex + xtypex + ' .layui-badge').html() * 1 >= 15) {
                        $('#test' + xtypex).hide();

                    }
                    //上传成功
                },
                error: function(data) {
                    //演示失败状态，并实现重传
                    layer.msg('上传失败:' + JSON.stringify(data));
                }
            });
        }

    });


    function loginURL(){
        var urlUser = "http://gxzlsq.taiyuehd.net/ajax.aspx?type=CustLoginFst" + "&txtFname=" + $("#txtFname").val() + "&idcard=" + escape($("#txtFcardno").val()) +
            "&phone=" + escape($("#txtPhone").val()) + "&userpwd=" + escape($("#txtPwd").val()) + "&t=" + new Date();
        window.open(urlUser);
    }

    function mainURL(){

        window.open("http://gxzlsq.taiyuehd.net/wap/tyhome.htm");
    }

    function statusURL(){
        var urlUser = "http://gxzlsq.taiyuehd.net/ajax.aspx?Type=getCustLoginStatus&t="+new Date();
        window.open(urlUser);
    }

    function setFno(){
        setCookie("custfnocookie",$("#fno").val());
        layer.msg('设置成功:' + getCookie("custfnocookie"));
    }
</script>
</body>

</html>